﻿Ext.QuickTips.init();
Ext.Ajax.timeout = 90000000;
Ext.form.Field.prototype.msgTarget = 'side';

function alertSucc1(msg) {
	Ext.Msg.show( {
		title : '亚信联创云管控系统',
		msg : msg,
		minWidth : 200,
		buttons : Ext.Msg.OK,
		icon : Ext.MessageBox.OK
	});
};
function alertError(msg) {
	Ext.Msg.show( {
		title : '亚信联创云管控系统',
		msg : msg,
		minWidth : 200,
		buttons : Ext.Msg.OK,
		icon : Ext.MessageBox.ERROR
	});
};
function alertInfo(msg) {
	Ext.Msg.show( {
		title : '亚信联创云管控系统',
		msg : msg,
		minWidth : 200,
		buttons : Ext.Msg.OK,
		icon : Ext.MessageBox.INFO
	});
};
function alertSucc(msg) {
	Ext.alert_msg.msg('友情提示',msg)
	/*Ext.Msg.show( {
		title : '亚信联创云管控系统',
		msg : msg,
		minWidth : 200,
		buttons : Ext.Msg.OK,
		icon : Ext.MessageBox.OK
	});*/
};




//重写 CheckboxSelectionModel
Ext.override(Ext.grid.CheckboxSelectionModel, { 
	handleMouseDown : function(g, rowIndex, e){   
	    if(e.button !== 0 || this.isLocked()){   
	        return;   
	    }   
	    var view = this.grid.getView();   
	    if(e.shiftKey && !this.singleSelect && this.last !== false){   
	        var last = this.last;   
	        this.selectRange(last, rowIndex, e.ctrlKey);   
	        this.last = last; // reset the last   
	        view.focusRow(rowIndex);   
	    }else{   
	        var isSelected = this.isSelected(rowIndex);   
	    if(isSelected){   
	        this.deselectRow(rowIndex);   
	}else if(!isSelected || this.getCount() > 1){   
	        this.selectRow(rowIndex, true);   
	        view.focusRow(rowIndex);   
	        }   
	    }   
	} 
	});



Ext.namespace("CDEXT", "CDEXT.grid");
CDEXT.PagingToolbarResizer = Ext.extend(Object, {
  options: [10,20, 25, 30, 40,50,60, 80, 100,200],
  mode: 'remote',
  displayText: '页大小：',
  prependCombo: false,
  constructor: function(config){
    Ext.apply(this, config);
    CDEXT.PagingToolbarResizer.superclass.constructor.call(this, config);
  },


  init : function(pagingToolbar) {
var comboStore = this.options;
 
    var combo = new Ext.form.ComboBox({
      typeAhead: false,
      triggerAction: 'all',
      forceSelection: true,
      selectOnFocus:true,
      lazyRender:true,
      editable: false,
      mode: this.mode,
      value: pagingToolbar.pageSize,
      width:40,
      listWidth:40,
      store: comboStore,
      listeners: {
        select: function(combo, value, i){
          pagingToolbar.pageSize = comboStore[i];
          pagingToolbar.doLoad(Math.floor(pagingToolbar.cursor/pagingToolbar.pageSize)*pagingToolbar.pageSize);
        }
      }
    });


    var index = 0;
    
    if (this.prependCombo){
     index = pagingToolbar.items.indexOf(pagingToolbar.first);
     index--;
    } else{
     index = pagingToolbar.items.indexOf(pagingToolbar.refresh);
        pagingToolbar.insert(++index,'-');
    }
    
    pagingToolbar.insert(++index, this.displayText);
    pagingToolbar.insert(++index, combo);
    
    if (this.prependCombo){
     pagingToolbar.insert(++index,'-');
    }
    
    //destroy combobox before destroying the paging toolbar
    pagingToolbar.on({
      beforedestroy: function(){
     combo.destroy();
      }
    });


  }
});

Ext.reg('pagingToolbarResizer',CDEXT.PagingToolbarResizer);
CDEXT.grid.PageGrid = Ext
		.extend(
				Ext.grid.GridPanel,
				{

					pageSize : 20,
					// private
					initBbar : function() {
						if (this.bbar !== false) {
							var displayMsg='显示第 {0} 条到第 {1} 条记录，一共 {2} 条';
							if(this.showsmpile){
							displayMsg='共 {2} 条记录'
							}
							var grid = this;
							this.bbar=new Ext.PagingToolbar( {
								beforePageText : "第",
								afterPageText : "页, 共{0}页",
								displayMsg : displayMsg,
								emptyMsg : "没有符合条件的记录",
								store : this.store,
								pageSize : this.pageSize,
								displayInfo : true,
								plugins : [new CDEXT.PagingToolbarResizer( { prependCombo: false})]
								});
							
						}
					},
					initComponent : function() {
						Ext
								.apply(
										this.viewConfig,
										{
											handleHdOver : function(e, t) {
												var hd = this.findHeaderCell(t);
												if (hd && !this.headersDisabled) {
													this.activeHd = hd;
													this.activeHdIndex = this
															.getCellIndex(hd);
													var fly = this.fly(hd);
													this.activeHdRegion = fly
															.getRegion();
													if (!this.cm
															.isFixed(this.activeHdIndex)) {
														fly
																.addClass("x-grid3-hd-over");
														this.activeHdBtn = fly
																.child('.x-grid3-hd-btn');
														if (this.activeHdBtn) {
															this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1)
																	+ 'px';
														}
													}
												}
											}
										});
						this.initBbar();
						if (this.isGroupHeader === true) {
							this.plugins = this.plugins || [];
							this.plugins
									.push(new Ext.ux.plugins.GroupHeaderGrid());
						}

						CDEXT.grid.PageGrid.superclass.initComponent.call(this);

						this.addEvents( {
							/**
							 * @event on beforeload
							 */
							'loadcheck' : true,

							/**
							 * @event on added
							 */
							'added' : true,

							/**
							 * @event on delete
							 */
							'beforedelete' : true,
							'deleteafter' : true
						});
					},

					// overwrite
					onRender : function(ct, position) {
						this.filter = this.filter || {};
						this.like = this.like || {};

						CDEXT.grid.PageGrid.superclass.onRender.call(this, ct,
								position);
					},

					/**
					 * 刷新Grid,加载数据
					 */
					reload : function() {
						var pageSize=this.pageSize;
						if(this.getBottomToolbar().pageSize){
							 pageSize=this.getBottomToolbar().pageSize;
						}
						var a = arguments || {}, lo = this.store.lastOptions
								|| {}, pn = lo.params || {};
						a.params = Ext.applyIf(a.params || {}, {
							start : 0,
							limit : pageSize
						});
						this.store.reload(a);
					}
				});
Ext.reg('pgrid', CDEXT.grid.PageGrid);
